# -*- coding: utf-8 -*-

from w.javascript.expression.translator import LinkPtr,Link,testLType, StringLink
from w.javascript.expression.protocol import PyProtocol

def toJS(what):
    return PyProtocol.serialize(what)

def fromJS(what):
    return PyProtocol.deserialize(what)

JS = LinkPtr()
JSS = StringLink

setattr(JS, 'ret', lambda a: 'return %s;'%(toJS(a) if testLType(a) else a))
setattr(JS, 'new', lambda a: Link('new %s'%(toJS(a) if testLType(a) else a)))
setattr(JS, 'var', lambda a: Link('var '+str(a)))
setattr(JS, 's', lambda a: StringLink(a))
